package com.abaaba.project2.controller;

import com.abaaba.project2.bean.GoodsDataSendingListBaseReq;
import com.abaaba.project2.bean.bo.AdminGoodsDeleteShoppingInformationBO;

import com.abaaba.project2.bean.vo.*;
import com.abaaba.project2.service.AdminCategoryService;
import com.abaaba.project2.service.AdminGoodsService;

import com.fasterxml.jackson.databind.ser.Serializers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/goods")
public class AdminGoodsController {

    @Autowired
    AdminGoodsService goodsService;


    @RequestMapping("list")
    public AdminGoodsDataSendingListVO goodsDataSendingList(GoodsDataSendingListBaseReq baseReq){
       // GoodsDataSendingListVO goodsDataSendingListVO = new GoodsDataSendingListVO();
        AdminGoodsDataSendingListVO goodsDataSendingListVO = goodsService.goodsSearchAll(baseReq);
        return goodsDataSendingListVO;
    }

    @RequestMapping("catAndBrand")
    public AdminGoodsAddShoppingInformationOfCatAndBrandVO adminGoodsAddShoppingInformation(){
        AdminGoodsAddShoppingInformationOfCatAndBrandVO adminGoodsAddShoppingInformation = goodsService.adminGoodsAddShoppingInformation();
        return adminGoodsAddShoppingInformation;
    }

    /*删除待定，还缺两个表的删除*/
    @RequestMapping("delete")
    public BaseRespVo adminGoodsDeleteShoppingInformation(@RequestBody AdminGoodsDeleteShoppingInformationBO adminGoodsDeleteShoppingInformationBO){
        /*删除失败的原因是，没有获取到数据*/

        //System.out.println("-----------------------");
        int code = goodsService.adminGoodsDeleteShoppingInformation(adminGoodsDeleteShoppingInformationBO);

        if (code == 200){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除失败");

    }

    @RequestMapping("create")
    public BaseRespVo adminGoodsCreatShoppingInformation(@RequestBody AdminGoodsAddShoppingInformationOfGoosListVO adminGoodsAddShoppingInformathonOfGoosListVO){
        int code = goodsService.adminGoodsCreatShopping(adminGoodsAddShoppingInformathonOfGoosListVO);

        if (code == 200){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("添加失败");
    }

    @RequestMapping("detail")
    public AdminGoodsAddShoppingInformationOfGoosListTwoVO adminGoodsUpdateShoppingInformation(Integer id){
        AdminGoodsAddShoppingInformationOfGoosListTwoVO code = goodsService.adminGoodsUpdateShoppingInformation(id);
        return code;
    }

    @RequestMapping("update")
    public  BaseRespVo adminGoodsUpdateShoppingInformationOfGoodsListVO(@RequestBody AdminGoodsUpdateShoppingInformationOfGoodsListVO adgs){
        int code = goodsService.adminGoodsUpdateShoppingInformationOfGoodsListVO(adgs);

        if (code == 200){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("修改失败");
    }
}
